package cn.imvc.app.controllers.member;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;

import cn.imvc.app.domains.FundFlowType;
import cn.imvc.app.domains.IPayChannel;
import cn.imvc.app.entities.DealerApply;
import cn.imvc.app.entities.DealerLevel;
import cn.imvc.app.models.DealerApplyModel;
import cn.imvc.app.models.DealerLevelModel;
import cn.imvc.app.models.DealerModel;
import cn.imvc.core.DialogBean;
import cn.imvc.core.Render;
import cn.imvc.data.domain.ViewRequest;
/**
 * 
 * @author wujx
 * @time 2016年7月19日
 *
 */
public class DealerApplyControllerImpl implements DealerApplyController {
	public Page<DealerApply> page;
	public ViewRequest viewRequest;
	private int id;
	@Autowired
	private DealerApplyModel dealerApplyModel;
	private DealerApply dealerApply;
	private Map<Byte,String> iPayChannel = IPayChannel.elMap;
	
	public String search() {
		return null;
	}

	public String index() {
		if (viewRequest == null) {
			viewRequest = new ViewRequest();
			// 获取当前日期
			try {
				Date date = new Date();
				SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
				String nowDate = sf.format(date);

				// 获取明天
				Calendar cal = Calendar.getInstance();
				cal.setTime(sf.parse(nowDate));
				cal.add(Calendar.DAY_OF_YEAR, +1);
				String nextDay = sf.format(cal.getTime());

				viewRequest.getParams().put("_and_d_dot_createdAt_ge_date", nowDate);
				viewRequest.getParams().put("_and_d_dot_createdAt_le_date", nextDay);
			} catch (ParseException e) {
				System.out.println("获取时间异常");
			}
		}
				viewRequest.getSort().put("d.createdAt", "DESC");
		
		page = dealerApplyModel.findAll(viewRequest);
		return "dealer-apply/index";
	}
	
	/**
	 *  分销商申请详情
	 */
	public String details(){
		dealerApply = dealerApplyModel.getOne(id);
		return "dealer-apply/detail";
	}
	 
	
	/**
	 * 分销商申请审核通过
	 */
	public String approved(){
		dealerApplyModel.updateApproved(id);
		return Render.json(new DialogBean("200", "审核通过","","closeCurrent"));
	}
	
	/**
	 * 分销商申请审核不通过
	 */
	public String notApproved(){
		dealerApplyModel.updateNotApproved(id);
		return Render.json(new DialogBean("200", "审核不通过","","closeCurrent"));
	}
	
	public String show() {
		// TODO Auto-generated method stub
		return null;
	}

	public String editNew() {
		// TODO Auto-generated method stub
		return null;
	}

	public String create() {
		// TODO Auto-generated method stub
		return null;
	}

	public String edit() {
		// TODO Auto-generated method stub
		return null;
	}

	public String update() {
		// TODO Auto-generated method stub
		return null;
	}

	public String destroy() {
		// TODO Auto-generated method stub
		return null;
	}

	public String destroyBatch() {
		// TODO Auto-generated method stub
		return null;
	}

	public Page<DealerApply> getPage() {
		return page;
	}

	public void setPage(Page<DealerApply> page) {
		this.page = page;
	}

	public ViewRequest getViewRequest() {
		return viewRequest;
	}

	public void setViewRequest(ViewRequest viewRequest) {
		this.viewRequest = viewRequest;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public DealerApply getDealerApply() {
		return dealerApply;
	}

	public void setDealerApply(DealerApply dealerApply) {
		this.dealerApply = dealerApply;
	}


	public Map<Byte, String> getIPayChannel() {
		return iPayChannel;
	}

	public void setIPayChannel(Map<Byte, String> iPayChannel) {
		this.iPayChannel = iPayChannel;
	}
}
